//
//  HSYBaseVideoPlayerViewController.m
//  高仿暴走斗图
//
//  Created by key on 16/6/20.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYBaseVideoPlayerViewController.h"
#import "HSYBaseVideoPlayerView+PanGestrues.h"

@interface HSYBaseVideoPlayerViewController ()

@property (nonatomic, strong, readonly) NSString *urlString;
@property (nonatomic, assign, readonly) BOOL isFullScreen;

@end

@implementation HSYBaseVideoPlayerViewController

- (instancetype)initWithVideoUrlString:(NSString *)urlString
{
    if (self = [super init]) {
        _urlString = urlString;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    @weakify(self);
    [self.view addSubview:[HSYBaseVideoPlayerView shareVolumeInstance]];
    _playerController = [HSYBaseVideoPlayerController showStremingPlayerControllerByVideoUrlString:self.urlString willTransformedSmallScreenBlock:^(NSNumber *value) {
        //大转小
        @strongify(self);
        _isFullScreen = NO;
        [self setNeedsStatusBarAppearanceUpdate];
    } willChangeToFullscreenModeBlock:^(NSNumber *value) {
        //小转大
        @strongify(self);
        _isFullScreen = YES;
        [self setNeedsStatusBarAppearanceUpdate];
    } dimissCompleteBlock:^{
        //移除
    } currentPlayTimeBlock:^(NSNumber *value) {
        
    }];
    self.playerController.isHidden = YES;
    [self.view addSubview:self.playerController.view];
}

#pragma mark - State Bar Update

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if (self.playerController) {
        [self.playerController rac_stopAllTimer];
    }
}

- (BOOL)prefersStatusBarHidden
{
    return self.isFullScreen;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
    return UIStatusBarAnimationFade;
}

@end
